using System;

namespace LannyPractiseCode
{
    public class ArrayStack
    {
        private int MaxSize;//栈的大小
        private int[] Stack;//数组模拟栈
        private int top=-1;//表示栈顶，初始化为-1

        public ArrayStack(int maxSize)
        {
            this.MaxSize=maxSize;
            Stack=new int[maxSize];
        }
        public bool IsFull()
        {
            return top==MaxSize-1;
        }
        public bool IsEmpty()
        {
            return -1==top;
        }
        //入栈
        public void Push(int value)
        {
            if(IsFull())
            {
                System.Console.WriteLine("栈已满！！！");
                return;
            }
            top++;
            Stack[top]=value;
        }

        //出栈
        public int Pop()
        {
            if(IsEmpty())
                throw new Exception("栈空。。");
            
            int result=Stack[top];
            top--;
            return result;
        }
        //遍历栈。。
        public void DisplayStack()
        {
            if(IsEmpty())
                return;

            for(int i=top;i>=0;i--)
            {
                System.Console.WriteLine(Stack[i]);
            }
        }

        //返回运算符的优先级。数字越大，优先级越高
        public int Priority(string oper)
        {
            if(oper=="*" || oper=="/")
                return 1;
            else if(oper=="+" || oper=="-")
                return 0;
            else 
                return -1;
        }
        //判断是不是运算符
        public bool IsOper(string val)
        {
            return val=="+" ||val=="-"||val=="*" ||val=="/";
        }

        public int Peek()
        {
            return Stack[top];
        }
        public int Cal(int num1,int num2,string oper)
        {
            int result=0;

            switch(oper)
            {
                case "+":
                    result=num1+num2;
                    break;
                case "-":
                    result=num2+num1;
                    break;
                case "*":
                    result=num1*num2;
                    break;
                case "/":
                    result=num2/num1;
                    break;
            }

            return result;
        }
    }
}